package chpt12;

import java.sql.*;

public class DBbasic4Update {
	public static void main(String[] args) {
		String url = "jdbc:mysql://127.0.0.1:3306/demoDB?serverTimezone=Asia/Chongqing";
		String userName = "root";
		String pwd = "root123";
		try(Connection con = DriverManager.getConnection(
				url, userName, pwd);
				Statement stmt = con.createStatement();) {
			String sql1 = "insert into students "
					+ "values(null, 'Js111','陈某',3.6,null)";
			String sql2 = "insert into students "
					+ "values(null, 'Js222','赵某',1.65,null)";
			String sql3 = "delete from students where name like '赵%'";
			String sql4 = "update students set gpa=2.8 where ID='2'";
			stmt.executeUpdate(sql1);
			stmt.executeUpdate(sql2);
			stmt.executeUpdate(sql3);
			stmt.executeUpdate(sql4);
			ResultSet rs = stmt.executeQuery("select * from students");
			while (rs.next())
				System.out.println("学号=" + rs.getString(2) + 
						"; 姓名=" + rs.getString("name") + 
						"; GPA=" + rs.getDouble(4));
		} catch (SQLException e) {
			e.printStackTrace();
		} 
	}
}
